//
//  HttpResponseData.swift
//  MT
//
//  Created by zhang qiang on 2018/11/21.
//  Copyright © 2018年 张强. All rights reserved.
//

import Foundation
import ObjectMapper


/// 请求成功code
public let RequestSuccessCodes  = [200]


/// 请求成功致命失败 出现此Code , 其他字段均为nil
public let RequestFatalErrorCodes = 0...9


/// 登录信息失效code
public let LoginInfoInvalidCode = 500


/// 请求服务器失败
public let RequestServerFailedString = "请求失败"


/// 请求数据基类
public class ResponseBaseData : Mappable{
    
    public var message : String!
    public var error   : String!
    public var code    : Int?
    
    public init(){
        
    }
    
    public required init?(map: Map) {
        
    }
    
    public func mapping(map: Map) {
        message <- map["message"]
        error <- map["error"]
        code <- map["code"]
     }
}


/// data 是一个封装的数据类型
final public class ResponseObjectData<T : Mappable> : ResponseBaseData{
     public var data : T?
    
    override  public func mapping(map: Map) {
        super.mapping(map: map)
        data <- map["data"]
    }
}


/// data 是一个数组 T 遵守BaseMappable
final public class ResponseArrayData<T : Mappable> : ResponseBaseData{
    public var data : Array<T>?
    
    override  public func mapping(map: Map) {
        super.mapping(map: map)
        data <- map["data"]
    }
}


/// data 基本数据类型
final public class ResponseOriginalData<T> : ResponseBaseData{
    public var data : T?

    override  public func mapping(map: Map) {
        super.mapping(map: map)
        data <- map["data"]
    }
}

